import { defineConfig } from 'vite'
import eslint from 'vite-plugin-eslint'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'

const apiProxyUrl = 'https://api.gongkaoleida.com/'
// const apiProxyUrl2 = 'http://ch.leida.cc/'
// const apiProxyUrl2 = 'http://channel.gkld.top/'
const apiProxyUrl2 = 'https://api.gongkaoleida.com/'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      template: {
        // 添加以下内容
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith('wx-')
        }
      }
    }),
    vueJsx({
      // 配置选项
    }),
    eslint({
      // 禁用缓存
      cache: false
    })
  ],
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/variables.scss";'
      }
    }
  },
  server: {
    https: false,
    open: false,
    port: 8080,
    host: '0.0.0.0',
    cors: true,
    proxy: {
      '/api': {
        target: apiProxyUrl,
        changeOrigin: true,
        secure: false
        // rewrite: (path) => path.replace(/^\/api/, 'api')
      },
      '/et': {
        target: apiProxyUrl,
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/et/, 'et')
      },
      '/chadmin': {
        target: apiProxyUrl2,
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/chadmin/, 'chadmin')
      }
    }
  },
  base: './'
})
